/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package threadmatriz;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author G0006185
 */
public class ThreadMatriz {
    private static  Long start,end;
    private String tempo;

    public String getTempo() {
        return tempo;
    }

    public void setTempo(String tempo) {
        this.tempo = tempo;
    }
    
    
      /**
     * @param args the command line arguments
     */
    private  int tam;
    private  int qtdThread;
    private  int k=1; 
    private  Matriz[] matriz = new Matriz[10];
    private  Thread[] mThread = new Thread[10];

    public void setTam(int tam) {
        this.tam = tam;
    }
    public void setQtdThread(int qtdThread) {
        this.qtdThread = qtdThread;
    }
    public  int runThread(double[][] a, double[][] b, double[][] c) throws InterruptedException{
        ThreadMatriz f = new ThreadMatriz();
        for (int i = 0; i < tam; i++)
           for (int j = 0; j < tam; j++) {
               a[i][j]= k;
               b[i][j]= k;
               k++;
           }
        //System.out.println( f.imprimeMatriz(b));
        start = System.currentTimeMillis();
         int limi = 0;
         int lims = tam/qtdThread;
         System.out.println(lims);
           for (int i = 0; i < qtdThread; i++) { 
                matriz[i] = new Matriz(a,b,c,tam);

                matriz[i].setMi(limi);
                matriz[i].setMf(lims);

                mThread[i]  = new Thread(matriz[i]);
                mThread[i]  = new Thread(matriz[i]);
                mThread[i].start();
                limi = lims;
                lims += tam/qtdThread;
           }
        mThread[qtdThread-1].join();
        end = System.currentTimeMillis();
        
        
        this.setTempo(new SimpleDateFormat("mm:ss").format(new Date(end-start)));
        
        //System.out.println(tempo);
        return 0;
       // f.imprimeMatriz(d);
    }

    public String imprimeMatriz(double d[][]){
        String mat="";
        int n = d.length; // linhas
        int m = d[0].length; //colunas
        int p = d[0].length;   
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < p; j++) 
                mat +=d[i][j]+"  ";
            mat +="\n";
        }
        return mat;
    }
}
